﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.Commands;
using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Data.MES.API.Dto.WorkDtos;
using B.S.Domain.BasicData.Factory_modeling.Production_line_management;
using B.S.Domain.BasicData.MaterialManagement.Product_material;
using B.S.Domain.Process.ProcessrouteName;
using B.S.Domain.基础数据.客户管理;
using B.S.Requst;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkOrderController : ControllerBase
    {
        private readonly IMediator _mediator;

        public WorkOrderController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 新增工单信息
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIRequst<int>> AddWorkOrder(CreateWorkOrderCommand command)
        {
            string CreateName = User.FindFirstValue("UserNickname");
            command.CreateName = CreateName;
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取客户信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<client>>> ShowClient()
        {
            return _mediator.Send(new ShowCustomerCommand());
        }
        /// <summary>
        /// 获取产品主数据信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<Product_material>>> GetProduct()
        {
            return _mediator.Send(new GetProduct_materialCommand());
        }
        /// <summary>
        /// 获取工艺路线信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<Processroute>>> GetProcessroute()
        {
            return _mediator.Send(new GetProcessrouteCommand());
        }
        /// <summary>
        /// 获取产线信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<Production_line_management>>> GetProduction_line()
        {
            return _mediator.Send(new GetProduction_line_managementCommand());
        }
        /// <summary>
        /// 条件查询+分页显示
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<WorkOrderDTO>>>> GetWorkOrder([FromQuery] GetWorkOrderCommand command)
        {
            return _mediator.Send(command);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="workid">根据编号删除</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public Task<APIRequst<int>> DelteWorkOrder(int workid)
        {
            string CreateName= User.FindFirstValue("UserNickname");
           
            DelteWorkOrderCommand command = new DelteWorkOrderCommand();
            command.workid = workid;
            command.DeleteName = CreateName;
            return _mediator.Send(command);
        }
        /// <summary>
        /// 更新工单信息
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public Task<APIRequst<int>> UpdateWorkOrder(UpdateWorkOrderCommand command)
        {
            return _mediator.Send(command);
        }
        /// <summary>
        /// 检验项目逻辑批量删除
        /// </summary>
        /// <param name="projectarray">编号数组</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public Task<APIRequst<int>> AllDeleteWorkOrder(string codeme)
        {
            AllDeleteWorkOrderCommand command = new AllDeleteWorkOrderCommand();
            command.Codeme = codeme; ;
            return _mediator.Send(command);
        }
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="workId">编号</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<int>> UpdateState(int workId)
        {
            UpdateStateCommand command = new UpdateStateCommand();
            command.workId = workId;
            return _mediator.Send(command);
        }
        /// <summary>
        /// 根据ID查询工单信息
        /// </summary>
        /// <param name="workId">工单ID</param>
        /// <returns>工单信息</returns>
        /// <summary>
        /// 获取所有工单（单表查询，无关联，无查询条件，无分页）
        /// </summary>
        /// <returns>工单列表</returns>

    }
}
